/// Author: Samle
import 'package:flutter/material.dart';

import 'ImageDetail.dart';

class BooksElement extends StatefulWidget {
  /// 传入参数
  const BooksElement({
    Key? key,
    required this.onPressed,
    required this.doublePressed,
    required this.longPressed,
    required this.onTap,
    required this.toDetail,
    required this.dataForm,
  }) : super(key: key,);
  final Map dataForm;
  final VoidCallback onPressed;
  final VoidCallback doublePressed;
  final VoidCallback longPressed;
  final VoidCallback onTap;
  final VoidCallback toDetail;
  @override
  State<StatefulWidget> createState() => BooksElementState();
}
class BooksElementState extends State<BooksElement> {

  @override
  Widget build(BuildContext context) {
    return Stack(
      alignment:Alignment.center , /// 指定对齐方式为居中
      children: <Widget>[          /// 子组件列表
        Positioned(                /// 不指定任何参数时则放在Stack对齐方式指定的位置
          child: InkWell(
              onTap: (){ widget.onPressed(); },
              onDoubleTap: (){ widget.doublePressed(); },
              onLongPress: (){ widget.longPressed(); },
              child: Stack(children: [
                Container(
                    padding: EdgeInsets.fromLTRB(8, 4, 8, 4),
                    decoration: BoxDecoration(
                      border:  Border(bottom:BorderSide(width: 1,color: Color(0xffe5e5e5)) ),
                    ),
                    child: Column(
                        children: [
                          Container(
                            padding: EdgeInsets.fromLTRB(8, 2, 8, 2),
                            child: Row(
                              children: [
                                Container(
                                  decoration: const BoxDecoration(color: Colors.white),
                                  alignment: Alignment.center,
                                  height: 120,
                                  width: 90,
                                  child:ImageDetail(widget.dataForm["cover"]),
                                ),
                                Container(
                                    width: MediaQuery.of(context).size.width - 122,
                                    height: 120,
                                    alignment: Alignment.bottomLeft,
                                    child: Column(
                                      children: [
                                        Container(
                                            padding: EdgeInsets.fromLTRB(8, 2, 8, 2),
                                            alignment: Alignment.bottomLeft,
                                            child: Text.rich(
                                                TextSpan(
                                                    children: [
                                                      TextSpan(text: widget.dataForm["name"] != null ? widget.dataForm["name"].toString() : '',style: TextStyle(color: Colors.black,fontSize: 16)),
                                                      TextSpan(text: ' ',style: TextStyle(color: Colors.black54,fontSize: 12)),
                                                      TextSpan(text: widget.dataForm["num"] != null ? widget.dataForm["num"].toString() : '',style: TextStyle(color: Colors.black54,fontSize: 12)),
                                                    ]
                                                )
                                            )
                                        ),
                                        Container(
                                            padding: EdgeInsets.fromLTRB(8, 2, 8, 2),
                                            alignment: Alignment.bottomLeft,
                                            child: Text.rich(
                                                TextSpan(
                                                    children: [
                                                      TextSpan(text: widget.dataForm["content"] != null ? widget.dataForm["content"].toString() : '',style: TextStyle(color: Colors.black54,fontSize: 12)),
                                                    ]
                                                )
                                            )
                                        ),
                                        // Container(
                                        //     padding: EdgeInsets.fromLTRB(8, 2, 8, 2),
                                        //     alignment: Alignment.bottomLeft,
                                        //     child: Text.rich(
                                        //         TextSpan(
                                        //             children: [
                                        //               TextSpan(text: '单词数量：',style: TextStyle(color: Colors.black54,fontSize: 12)),
                                        //               TextSpan(text: widget.dataForm["num"] != null ? widget.dataForm["num"].toString() : '',style: TextStyle(color: Colors.black54,fontSize: 12)),
                                        //             ]
                                        //         )
                                        //     )
                                        // ),
                                        // Container(
                                        //     padding: EdgeInsets.fromLTRB(8, 2, 8, 2),
                                        //     alignment: Alignment.bottomLeft,
                                        //     child: Text.rich(
                                        //         TextSpan(
                                        //             children: [
                                        //               // TextSpan(text: '资源地址：',style: TextStyle(color: Colors.black54,fontSize: 12)),
                                        //               TextSpan(text: widget.dataForm["path"] != null ? widget.dataForm["path"].toString() : '',style: TextStyle(color: Colors.black54,fontSize: 12)),
                                        //             ]
                                        //         )
                                        //     )
                                        // ),
                                      ],
                                    )
                                )
                              ],
                            ),
                          ),


                        ]
                    )
                ),
                Positioned(
                  right: 50, //距离左边18px
                  bottom: 10, //距离顶部27px
                  child: TextButton(
                    onPressed: () {
                      widget.toDetail();
                    },
                    child: Text("查看"),
                  )
                  // InkWell(
                  //   child: Text("查看"),
                  //   onTap: () {
                  //     widget.toDetail();
                  //   },
                  // )
                  // IconButton(
                  //   icon: const Icon(Icons.output,color: Colors.black54,),
                  //   onPressed: () {
                  //     widget.toDetail();
                  //   },
                  // ),
                ),
                Positioned(
                  right: 15, //距离左边18px
                  bottom: 10, //距离顶部27px
                  child: IconButton(
                    icon: const Icon(Icons.download_outlined,color: Colors.black54,),
                    onPressed: () {
                      widget.onTap();
                    },
                  ),
                )
              ],)
          ),
        ),
        /// Positioned(
        /// right: 15,
        /// top: 0,
        /// child: Container(
        /// child: Text(""),
        /// decoration: BoxDecoration(
        /// borderRadius: BorderRadius.only(
        /// bottomLeft: Radius.circular(5.0),
        /// bottomRight: Radius.circular(5.0)
        /// ),
        /// ),
        /// padding: EdgeInsets.fromLTRB(3, 2, 3, 4),
        /// ),
        /// ),
      ],
    );
  }

}

